home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / reuse.lha / reuse / m2c / SetsDrv.c < prev    next >
C/C++ Source or Header  |  1992-08-18  |  4KB  |  132 lines

  1. #include "SYSTEM_.h"
  2.  
  3. #ifndef DEFINITION_Sets
  4. #include "Sets.h"
  5. #endif
  6.  
  7. #ifndef DEFINITION_IO
  8. #include "IO.h"
  9. #endif
  10.  
  11. #define max    1000
  12. static Sets_tSet s, t, u;
  13. static CARDINAL i;
  14. static IO_tFile f;
  15.  
  16.  
  17. void BEGIN_MODULE()
  18. {
  19.   BEGIN_Sets();
  20.   BEGIN_IO();
  21.  
  22.   Sets_MakeSet(&s, (LONGCARD)max);
  23.   Sets_MakeSet(&t, (LONGCARD)max);
  24.   Sets_MakeSet(&u, (LONGCARD)max);
  25.   for (i = 2; i <= max; i += 1) {
  26.     Sets_Include(&t, i);
  27.   }
  28.   Sets_AssignEmpty(&s);
  29.   Sets_AssignElmt(&s, 1L);
  30.   Sets_Assign(&u, t);
  31.   Sets_Union(&s, t);
  32.   Sets_AssignEmpty(&t);
  33.   for (i = 0; i <= max; i += 2) {
  34.     Sets_Include(&t, i);
  35.   }
  36.   Sets_Difference(&s, t);
  37.   for (i = 0; i <= max; i += 3) {
  38.     Sets_Exclude(&s, i);
  39.   }
  40.   for (i = 0; i <= max; i += 5) {
  41.     Sets_Exclude(&s, i);
  42.   }
  43.   for (i = 0; i <= max; i += 7) {
  44.     Sets_Exclude(&s, i);
  45.   }
  46.   for (i = 0; i <= max; i += 11) {
  47.     Sets_Exclude(&s, i);
  48.   }
  49.   for (i = 0; i <= max; i += 13) {
  50.     Sets_Exclude(&s, i);
  51.   }
  52.   for (i = 0; i <= max; i += 17) {
  53.     Sets_Exclude(&s, i);
  54.   }
  55.   for (i = 0; i <= max; i += 19) {
  56.     Sets_Exclude(&s, i);
  57.   }
  58.   for (i = 0; i <= max; i += 23) {
  59.     Sets_Exclude(&s, i);
  60.   }
  61.   for (i = 0; i <= max; i += 29) {
  62.     Sets_Exclude(&s, i);
  63.   }
  64.   f = IO_WriteOpen((STRING)"/tmp/t", 6L);
  65.   Sets_WriteSet(f, s);
  66.   IO_WriteNl(f);
  67.   IO_WriteClose(f);
  68.   f = IO_ReadOpen((STRING)"/tmp/t", 6L);
  69.   Sets_ReadSet(f, &t);
  70.   IO_ReadClose(f);
  71.   Sets_WriteSet((System_tFile)IO_StdOutput, t);
  72.   IO_WriteNl((System_tFile)IO_StdOutput);
  73.   IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Sets_Size(&t), 5L);
  74.   IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Sets_Card(&t), 5L);
  75.   IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Sets_Minimum(&t), 5L);
  76.   IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Sets_Maximum(&t), 5L);
  77.   IO_WriteNl((System_tFile)IO_StdOutput);
  78.   Sets_AssignEmpty(&u);
  79.   for (i = 7; i <= max; i += 10) {
  80.     Sets_Include(&u, i);
  81.   }
  82.   Sets_WriteSet((System_tFile)IO_StdOutput, u);
  83.   IO_WriteNl((System_tFile)IO_StdOutput);
  84.   IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Sets_Size(&u), 5L);
  85.   IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Sets_Card(&u), 5L);
  86.   IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Sets_Minimum(&u), 5L);
  87.   IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Sets_Maximum(&u), 5L);
  88.   IO_WriteNl((System_tFile)IO_StdOutput);
  89.   Sets_Intersection(&u, t);
  90.   Sets_WriteSet((System_tFile)IO_StdOutput, u);
  91.   IO_WriteNl((System_tFile)IO_StdOutput);
  92.   IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Sets_Size(&u), 5L);
  93.   IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Sets_Card(&u), 5L);
  94.   IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Sets_Minimum(&u), 5L);
  95.   IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Sets_Maximum(&u), 5L);
  96.   IO_WriteNl((System_tFile)IO_StdOutput);
  97.   Sets_ReleaseSet(&s);
  98.   Sets_ReleaseSet(&t);
  99.   Sets_ReleaseSet(&u);
  100.   Sets_MakeSet(&s, 10L);
  101.   Sets_Include(&s, 3L);
  102.   Sets_Include(&s, 7L);
  103.   IO_WriteNl((System_tFile)IO_StdOutput);
  104.   IO_WriteS((System_tFile)IO_StdOutput, (STRING)"enter Size and Set like below! (Size=0 terminates)", 50L);
  105.   IO_WriteNl((System_tFile)IO_StdOutput);
  106.   IO_WriteS((System_tFile)IO_StdOutput, (STRING)"10 ", 3L);
  107.   Sets_WriteSet((System_tFile)IO_StdOutput, s);
  108.   IO_WriteNl((System_tFile)IO_StdOutput);
  109.   Sets_ReleaseSet(&s);
  110.   for (;;) {
  111.     IO_WriteNl((System_tFile)IO_StdOutput);
  112.     IO_WriteFlush((System_tFile)IO_StdOutput);
  113.     i = IO_ReadI((System_tFile)IO_StdInput);
  114.     if (i == 0) {
  115.       goto EXIT_1;
  116.     }
  117.     Sets_MakeSet(&s, i);
  118.     Sets_ReadSet((System_tFile)IO_StdInput, &s);
  119.     Sets_WriteSet((System_tFile)IO_StdOutput, s);
  120.     IO_WriteS((System_tFile)IO_StdOutput, (STRING)" Card = ", 8L);
  121.     IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Sets_Card(&s), 0L);
  122.     IO_WriteNl((System_tFile)IO_StdOutput);
  123.     Sets_Complement(&s);
  124.     Sets_WriteSet((System_tFile)IO_StdOutput, s);
  125.     IO_WriteS((System_tFile)IO_StdOutput, (STRING)" Card = ", 8L);
  126.     IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Sets_Card(&s), 0L);
  127.     IO_WriteNl((System_tFile)IO_StdOutput);
  128.     Sets_ReleaseSet(&s);
  129.   } EXIT_1:;
  130.   IO_CloseIO();
  131. }
  132.